import java.util.Arrays;

public class MyStack {
    private int[] elem;
    private int usedsize;

    private static final  int DEFAILT_CAPACITY = 10;
    public MyStack(){
        this.elem = new int[DEFAILT_CAPACITY];
    }

     public void push(int val){
        if(!isfull(this.usedsize)){
            this.elem = Arrays.copyOf(this.elem,this.elem.length*2);
        }
        this.elem[usedsize] = val;
        this.usedsize++;

     }

     public boolean isfull(int usedsize){
        if(usedsize > this.elem.length){
            return  false;
        }
        return true;
     }

     public int pop(){
        if(isEmpty()){
            int ret = this.elem[this.usedsize - 1];
            this.usedsize--;
            return ret;
        }else {
            throw new MyArrayIndexOutOfBoundsException();
        }

     }
     public int peek(){
         if(isEmpty()){
             return this.elem[usedsize - 1];
         }else {
             throw new MyArrayIndexOutOfBoundsException();
         }
     }
     public boolean isEmpty(){
        if(usedsize == 0){
            return false;
        }
        return true;
     }


}
